using JGSY.CMS.LowCode.Platform.Application.Interfaces;
using JGSY.CMS.LowCode.Platform.Application.DTOs;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JGSY.CMS.LowCode.Platform.Controllers
{
    /// <summary>
    /// 安全事件管理接口。
    /// 提供安全事件记录、查询、分析等相关功能的 API。
    /// </summary>
    [ApiController]
    [Route("api/security-events")]
    public class SecurityEventController : ControllerBase
    {
        /// <summary>
        /// 安全事件应用服务接口
        /// </summary>
        private readonly ISecurityEventAppService _service;
        
        /// <summary>
        /// 构造函数，注入安全事件服务
        /// </summary>
        /// <param name="service">安全事件应用服务接口</param>
        public SecurityEventController(ISecurityEventAppService service)
        {
            _service = service;
        }
        
        /// <summary>
        /// 获取所有安全事件列表
        /// </summary>
        /// <returns>安全事件列表</returns>
        [HttpGet]
        public async Task<IEnumerable<SecurityEventDto>> GetAll()
        {
            return await _service.GetAllAsync();
        }
        
        /// <summary>
        /// 根据ID获取指定安全事件信息
        /// </summary>
        /// <param name="id">安全事件ID</param>
        /// <returns>安全事件信息，如果未找到返回404</returns>
        [HttpGet("{id}")]
        public async Task<ActionResult<SecurityEventDto>> GetById(long id)
        {
            var result = await _service.GetByIdAsync(id);
            if (result == null) return NotFound();
            return result;
        }
        
        /// <summary>
        /// 添加新安全事件
        /// </summary>
        /// <param name="dto">安全事件数据传输对象</param>
        /// <returns>添加结果</returns>
        [HttpPost]
        public async Task<IActionResult> Add(SecurityEventDto dto)
        {
            await _service.AddAsync(dto);
            return Ok();
        }
        
        /// <summary>
        /// 更新指定安全事件信息
        /// </summary>
        /// <param name="id">安全事件ID</param>
        /// <param name="dto">安全事件数据传输对象</param>
        /// <returns>更新结果</returns>
        [HttpPut("{id}")]
        public async Task<IActionResult> Update(long id, SecurityEventDto dto)
        {
            await _service.UpdateAsync(id, dto);
            return Ok();
        }
        
        /// <summary>
        /// 删除指定安全事件
        /// </summary>
        /// <param name="id">安全事件ID</param>
        /// <returns>删除结果</returns>
        [HttpDelete("{id}")]
        public async Task<IActionResult> Delete(long id)
        {
            await _service.DeleteAsync(id);
            return Ok();
        }
    }
}
